public class Problem30 {
	public static void main(String[] args) {
		int i = 2;
		int sum = 0;
		//with n digit number Xn-1Xn-2Xn-3...X0 <= 9^5 * n

		for (; i <= 59045*6; ++i) {
			int s = 0;
			int m = i;
			while (m > 0) {
				s += Math.pow(m%10, 5);
				m /= 10;
			}

			if (s == i)
				sum += i;
		}

		System.out.println("" + sum);
	}
}
